package store.lunangangster.engine.impl.entity;

import java.util.HashMap;
import java.util.Map;

public class IdentityLinkEntityImpl extends EntityImpl implements IdentityLinkEntity {

  // DB property
  protected String executionId;
  protected String taskId;
  protected String type;
  protected String user;
  protected String group;

  // cache
  protected TaskEntity taskEntity;

  @Override
  public String getExecutionId() {
    return executionId;
  }

  @Override
  public String getTaskId() {
    return taskId;
  }

  @Override
  public String getType() {
    return type;
  }

  @Override
  public String getUser() {
    return user;
  }

  @Override
  public void setExecutionId(String executionId) {
    this.executionId = executionId;
  }

  @Override
  public void setTaskId(String taskId) {
    this.taskId = taskId;
  }

  @Override
  public void setType(String type) {
    this.type = type;
  }

  @Override
  public void setUser(String user) {
    this.user = user;
  }

  @Override
  public String getGroup() {
    return group;
  }

  @Override
  public void setGroup(String group) {
    this.group = group;
  }

  @Override
  public void setTask(TaskEntity taskEntity) {
    if (taskEntity != null) {
      this.taskId = taskEntity.getId();
    }
    this.taskEntity = taskEntity;
  }

  @Override
  public TaskEntity getTask() {
    return taskEntity;
  }

  @Override
  public Object getPersistState() {
    Map<String, Object> persistState = new HashMap<>();

    persistState.put("executionId", executionId);
    persistState.put("taskId", taskId);
    persistState.put("type", type);
    persistState.put("user", user);
    persistState.put("group", group);

    return persistState;
  }
}
